package com.wang.controller;

import com.wang.reponse.ChatMessageVo;
import com.wang.reponse.ChatSessionVo;
import com.wang.result.BaseResponse;
import com.wang.result.ResultUtils;
import com.wang.user.model.ChatMessage;
import com.wang.user.service.ChatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 聊天控制器
 */
@RestController
@RequestMapping("/chat")
@Api(tags = "聊天管理")
public class ChatController {

    @Resource
    private ChatService chatService;

    @PostMapping("/send")
    @ApiOperation(value = "发送消息")
    public BaseResponse<Boolean> sendMessage(@RequestBody ChatMessage message) {
        return ResultUtils.success(chatService.sendMessage(message));
    }

    @GetMapping("/history/{targetId}")
    @ApiOperation(value = "获取聊天历史记录")
    public BaseResponse<List<ChatMessageVo>> getChatHistory(@PathVariable("targetId") Integer targetId) {
        return ResultUtils.success(chatService.getChatHistory(targetId));
    }

    @GetMapping("/sessions")
    @ApiOperation(value = "获取会话列表")
    public BaseResponse<List<ChatSessionVo>> getSessionList() {
        return ResultUtils.success(chatService.getSessionList());
    }

    @PostMapping("/read/{targetId}")
    @ApiOperation(value = "标记消息为已读")
    public BaseResponse<Boolean> markAsRead(@PathVariable("targetId") Integer targetId) {
        return ResultUtils.success(chatService.markAsRead(targetId));
    }

    @GetMapping("/unread/count")
    @ApiOperation(value = "获取未读消息数")
    public BaseResponse<Integer> getUnreadCount() {
        return ResultUtils.success(chatService.getUnreadCount());
    }
} 